<?php
	require '../global.php';
	$db_config = require ROOT.'/tool/database/common.php';
	$db_config = require ROOT.'/tool/database/data.php';
	
	if(isset($_POST['name'])){
		//保存
		$name = $_POST['name'];
		$module = $_POST['module'];
		$table_name = $_POST['table_name'];
		$description = $_POST['description'];
		$db_config['tables'][$table_name]['name'] = $name;
		$db_config['tables'][$table_name]['description'] = $description;
		$db_config['tables'][$table_name]['module'] = $module;
		save_data_config($db_config);
		exit;
	}else{
		$name = $_GET['name'];
		$table_info = $db_config['tables'][$name];
		$modules = $db_config['module'];
	}
?>
<style>
	.edit_table{width:100%;background:white;}
	.edit_table label{display: inline-block;}
	.edit_table textarea{width:400px;height:50px;}
	.edit_table .opt{text-align: center;}
</style>
<form action="/tool/database/table_edit.php" method="post" id="table_info_form">
	<table class="edit_table">
		<colgroup>
			<col width="20%"/>
			<col width="50%"/>
			<col width="30%"/>
		</colgroup>
		<tr>
			<th>名称：</th>
			<td><input type="text" name="name" value="<?php echo $table_info['name']?>"></td>
			<td>中文名</td>
		</tr>
		<tr>
			<th>类别：</th>
			<td colspan="2">
				<?php 
					foreach ($modules as $key=>$module){
						$checked = '';
						if(!empty($table_info['module'])){
							foreach ($table_info['module'] as $m){
								if($m == $key){
									$checked = ' checked="checked"';
									break;
								}
							}
							
						}
				?>
				<label>
					<input type="checkbox" name="module[]"<?php echo $checked?> value="<?php echo $key?>"> <?php echo $module['name']?>
				</label>
				<?php 
					}
				?>
				</select>
			</td>
		</tr>
		<tr>
			<th>备注：</th>
			<td colspan="2">
				<textarea name="description"><?php echo $table_info['description']?></textarea>
			</td>
		</tr>
		<tr>
			<th></th>
			<td></td>
			<td></td>
		</tr>
		<tr>
			<td class="opt" colspan="3">
				<input type="hidden" name="table_name" value="<?php echo $name;?>" />
				<input type="button" id="table_info_edit_btn" value="保存"/>
			</td>
		</tr>
	</table>
</form>
<script type="text/javascript" language="javascript">
	$(function(){
		$("#table_info_edit_btn").click(function(){
             var options = {
                     url:$(this).attr("action"),   
                     type:'POST',   
                     success: function(){
            	 	$("#table_dia").dialog("close");
                     } 
                 };   
                 $('#table_info_form').ajaxSubmit(options);   
                 return false;  
		});
	});
</script>